Skip to content

Method: lambda$0(HasUri, HasUri)

1: /**
2: * Copyright (C) 2023 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.test.environment.util;
16:
17: import cz.cvut.kbss.jopa.test.HasUri;
18: import org.hamcrest.Description;
19: import org.hamcrest.TypeSafeMatcher;
20:
21: import java.util.Collection;
22: import java.util.Objects;
23:
24: /**
25: * Checks whether the provided collection contains the same entities as the expected one.
26: * <p>
27: * The membership check is done based on entity URIs.
28: *
29: * Item order is not significant in the comparison, but the total number of items is.
30: */
31: public class ContainsSameEntities extends TypeSafeMatcher<Collection<? extends HasUri>> {
32:
33: private final Collection<? extends HasUri> expected;
34:
35: public ContainsSameEntities(Collection<? extends HasUri> expected) {
36: this.expected = Objects.requireNonNull(expected);
37: }
38:
39: @Override
40: protected boolean matchesSafely(Collection<? extends HasUri> actual) {
41: if (actual == null || actual.size() != expected.size()) {
42: return false;
43: }
44: for (HasUri e : expected) {
45: if (actual.stream().noneMatch(ee -> Objects.equals(e.getUri(), ee.getUri()))) {
46: return false;
47: }
48: }
49: return true;
50: }
51:
52: @Override
53: public void describeTo(Description description) {
54: description.appendValueList("[", ", ", "]", expected);
55: }
56:
57: public static ContainsSameEntities containsSameEntities(Collection<? extends HasUri> expected) {
58: return new ContainsSameEntities(expected);
59: }
60: }